package com.hbnu.controller;

import com.hbnu.domain.Books;
import com.hbnu.domain.UserInfo;
import com.hbnu.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;

import java.util.Scanner;

@Controller
public class UserController {

    @Autowired
    private UserService userService;

    @Autowired
    private BooksController booksController;

    //登录方法
    public UserInfo userLogin(String uname, String upsw) {
        UserInfo loginUser = userService.findUserByUnameAndUpsw(uname, upsw);
        return loginUser;//返回用户信息
    }

    //角色功能方法
    //1.基本功能
    public void basicFuc(int n) {
        Scanner sc = new Scanner(System.in);
        if (n == 1) {
            System.out.println("请输入您要借阅的图书编号：(例如：1002)");
            int bid = sc.nextInt();

            booksController.borrowBook(bid);
        } else if (n == 2) {
            System.out.println("请输入您要还入的图书编号：(例如：1002)");
            int bid = sc.nextInt();

            booksController.backBook(bid);
        }
    }

    //2.高级功能
    public void advanceFuc(int i) {
        Scanner sc = new Scanner(System.in);
        if (i == 1) {
            System.out.println("请填写您要添加的图书信息：(输入书名，作者，出版设，数量 以空格分隔)");
            String bname = sc.next();
            String bauthor = sc.next();
            String bpublisher = sc.next();
            int bnumber = sc.nextInt();
            Books book = new Books(bname, bauthor, bpublisher, bnumber);

            booksController.newBook(book);
        } else if (i == 2) {
            System.out.println("请键入您需要修改的图书信息：(输入编号，书名，作者，出版设，数量 以空格分隔) ");
            int bid = sc.nextInt();
            String bname = sc.next();
            String bauthor = sc.next();
            String bpublisher = sc.next();
            int bnumber = sc.nextInt();
            Books book = new Books(bid, bname, bauthor, bpublisher, bnumber);

            booksController.modifyBook(book);
        } else {
            System.out.println("请输入您要删除的图书编号：(例如：1002)");
            int bid = sc.nextInt();

            booksController.cutBook(bid);
        }
    }
}
